package yz;

/**
 * [面试题 16.15. 珠玑妙算](https://leetcode-cn.com/problems/master-mind-lcci/)
 *
 * @author Yz
 * @since 2022-09-21 15:40
 */
public class LeetCode1615_MasterMind {
    public int[] masterMind(String solution, String guess) {
        int m = 0;
        int n = 0;
        char[] a = new char[4];
        char[] b = new char[4];
        for (int i = 0; i < 4; i++) {
            if (solution.charAt(i) == guess.charAt(i)) {
                m++;
                a[i] = ' ';
                b[i] = ' ';
            } else {
                a[i] = solution.charAt(i);
                b[i] = guess.charAt(i);
            }
        }
        for (int i = 0; i < 4; i++) {
            char c1 = b[i];
            if (c1 != ' ') {
                for (int k = 0; k < 4; k++) {
                    if (c1 == a[k]) {
                        a[k] = ' ';
                        b[i] = ' ';
                        n++;
                        break;
                    }
                }
            }
        }
        return new int[]{m, n};
    }
}
